package cool.lichuan.controller;

import lombok.RequiredArgsConstructor;
import net.dreamlu.iot.mqtt.spring.server.MqttServerTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * MQTT服务端接口
 *
 * @author lichuan
 * @since 2025/6/7 21:03
 */
@RestController
@RequiredArgsConstructor
public class TestPublishController {
    private final MqttServerTemplate mqttServerTemplate;

    @GetMapping("/test/publish")
    public void testPublish() {
        // 向所有订阅topic的客户端发送消息
        mqttServerTemplate.publishAll("/mqtt/testpublish", "mqtt server publishAll message".getBytes());
        // 向指定客户端发送消息
        mqttServerTemplate.publish("mqttx_f1e5c583", "/mqtt/testpublish", "mqtt server publish message".getBytes());
    }
}
